﻿using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System.Linq.Expressions;

namespace Citi.HeadCount.Domain.Mapping
{
    public class EntityMapping<T> : ClassMapping<T> where T : EntityBase
    {
        public EntityMapping()
        {
            Id(x => x.Id, map => { map.Generator(Generators.Identity); map.Column("Id"); });
            MapDates();
        }

        private void MapDates()
        {
            Property(x => x.ReferenceDate, m => { m.NotNullable(true); });
            Property(x => x.LastUpdate, m => { m.NotNullable(true); });
        }

        public EntityMapping(bool identity, bool withoutDate = false)
        {
            if (!identity)
                Id(x => x.Id, map => map.Column("Id"));
            else
                Id(x => x.Id, map => { map.Generator(Generators.Identity); map.Column("Id"); });

            if (!withoutDate)
                MapDates();
        }

        public EntityMapping(string namePrimaryColumn)
        {
            Id(namePrimaryColumn, map => map.Column(namePrimaryColumn));
            MapDates();
        }
    }
}